<template>
  <div class="gun-preview-container">
    <div class="action" v-if="isLoadData">
      <el-button type="text" @click="toEditPage">编辑</el-button>
    </div>
    <div
      class="main-content"
      v-if="parkEnvironmentCameraList || parkEquipmentEnvironmentCameraVoList"
    >
      <div class="gun-box">
        <div
          class="gun-group"
          v-if="parkEquipmentEnvironmentCameraVoList && parkEquipmentEnvironmentCameraVoList.length"
        >
          <div
            class="gun-item"
            v-for="(item, index) in parkEquipmentEnvironmentCameraVoList"
            :key="item.id"
          >
            <div class="name">环境枪{{ parkEquipmentEnvironmentCameraLength - index }}</div>
            <div class="gun-bd">
              <div class="channel-info-item">
                <div class="info-name">关联通道:</div>

                <div
                  class="bd"
                  v-if="item.channleCheckedNames.length < 2"
                >{{ item.channleCheckedNames.join(' , ') }}</div>

                <el-tooltip placement="bottom-start" v-if="item.channleCheckedNames.length >= 2">
                  <div slot="content">
                    <div
                      v-for="item in item.channleCheckedNames"
                      style="margin-bottom: 4px; font-size: 13px;"
                    >{{ item }}</div>
                  </div>
                  <div class="bd">{{ item.channleCheckedNames.join(' , ') }}</div>
                </el-tooltip>
              </div>
              <div class="video-info-item">
                <div class="info-name">视频流地址:</div>
                <el-tooltip
                  :content="item.ezvizAfterParam"
                  placement="bottom-start"
                  v-if="item.ezvizAfterParam"
                >
                  <div class="bd">{{ item.ezvizAfterParam }}</div>
                </el-tooltip>
              </div>
            </div>
          </div>
        </div>
        <div class="gun-group" v-if="parkEnvironmentCameraList">
          <div class="gun-item" v-for="(item, index) in parkEnvironmentCameraList" :key="item.id">
            <div class="name">通道枪{{ index + 1 }}</div>
            <div class="gun-bd">
              <div class="channel-info-item">
                <div class="info-name">关联通道:</div>
                <div class="bd">{{ item.equipmentRecognitionCameraName }}</div>
              </div>
              <div class="video-info-item">
                <div class="info-name">视频流地址:</div>
                <el-tooltip
                  :content="item.ezvizAfterParam"
                  placement="bottom-start"
                  v-if="item.ezvizAfterParam"
                >
                  <div class="bd">{{ item.ezvizAfterParam }}</div>
                </el-tooltip>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isLoadData: false,
      parkEnvironmentCameraList: null,
      parkEquipmentEnvironmentCameraVoList: null,
      selectOptChannelOpt: [],
      parkEquipmentEnvironmentCameraLength: 0, //环境枪通道列表长度
      isCentralMonitor: null
    };
  },
  created() {
    this.getList();
  },
  methods: {
    async getList() {
      await this.getParkinglotChannels();
      API.fetchGet("/operatorPark/getOperatorParkCentralMonitorResponse", {
        parkID: this.$route.query.parkId
      }).then(res => {
        this.isCentralMonitor = res.data.isCentralMonitor;
        if (res.data.parkEquipmentEnvironmentCameraVoList) {
          this.origin_parkEquipmentEnvironmentCameraVoList = JSON.parse(
            JSON.stringify(res.data.parkEquipmentEnvironmentCameraVoList)
          );
          this.parkEquipmentEnvironmentCameraVoList = res.data.parkEquipmentEnvironmentCameraVoList.map(
            item => {
              let ids = JSON.parse(JSON.stringify(item.channelIdList));
              item.channleCheckedNames = ids.map(item => {
                return this.selectOptChannelOpt.find(citem => citem.id === item)
                  .entranceName;
              });
              return item;
            }
          );
        }

        this.parkEnvironmentCameraList = res.data.parkEnvironmentCameraList;
        if (res.data.parkEnvironmentCameraList) {
          this.parkEquipmentEnvironmentCameraLength =
            this.parkEquipmentEnvironmentCameraVoList.length || 0;
        }

        this.isLoadData = true;
      });
    },
    //获取停车场所有通道
    getParkinglotChannels() {
      API.fetchGet(`/operatorPark/byParkID/${this.$route.query.parkId}`).then(
        res => {
          this.selectOptChannelOpt = res.data.map(item => {
            return {
              id: item.id,
              entranceName: item.entranceName
            };
          });
        }
      );
    },
    toEditPage() {
      this.$router.push({
        path: "/parkingLot/allParkingLot/deviceSetting",
        query: this.isCentralMonitor
          ? Object.assign(this.$route.query, {
              isCentralMonitor: this.isCentralMonitor
            })
          : Object.assign(this.$route.query, {
              isCentralMonitor: ''
            })
      });
    }
  },
  filters: {
    channelStr(value) {
      return value.join(",");
    }
  }
};
</script>

<style lang="less" scoped>
.main-content {
  margin: 0 20px;
  margin-top: 20px;
  padding-bottom: 40px;
}

.action {
  padding-left: 20px;
  margin-top: 10px;
  padding-right: 20px;
  display: flex;
  justify-content: flex-end;
}

.gun-group {
  padding-bottom: 20px;
  &:not(:last-child) {
    border-bottom: 1px dashed #c2c2c2;
  }
  &:not(:first-child) {
    padding-top: 20px;
  }
  .gun-item {
    display: flex;
    background: #f2f2f2;
    border-radius: 6px;
    padding-left: 20px;
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
    .name {
      height: 44px;
      line-height: 44px;
      font-size: 14px;
      color: #474747;
      margin-right: 40px;
      width: 70px;
    }
    .gun-bd {
      flex: 1;
      display: flex;
      align-items: center;
      .channel-info-item {
        width: 320px;
        display: flex;
        height: 44px;
        line-height: 44px;
        padding-right: 50px;
        .bd {
          width: 204px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          padding-left: 10px;
        }
      }
      .video-info-item {
        // width: 450px;
        display: flex;
        height: 44px;
        line-height: 44px;
        .bd {
          width: 360px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          padding-left: 10px;
        }
      }
    }
  }
}
</style>
